import $store from '@/store/index.js';
import util from '@/libs/util.js';
import {router} from '@/router/index.js';
import Vue from 'vue';
var $vue=new Vue();
export const  columns4=[
        {
            type: 'selection',
            width: 60,
            align: 'center'
        },
        {
            title: 'ID',
            key: 'Id',
            width: 80,
            align: 'center',
        },
        {
            title: '试卷名称',
            align: 'center',
            key: 'name'
        },
        {
            title: '试卷类型',
            align: 'center',
            key: 'type',
            render:function(h,params){
            	var str='';
            	switch (params.row.type){
            		case 1:str='模拟试卷';break;
            		case 2:str='正式试卷';break;
            		case 3:str='公用试卷';break;
            	}
            	return h('div',str)
            }
        },
        {
            title: '更新时间',
            align: 'center',
            key: 'updateTime',
            render:function(h,params){
                return h('div',util.timestampToTime(params.row.updateTime))
            }
        },
        {
            title: '试卷状态',
            align: 'center',
            key: 'status',
            //1启用，0禁用
            render:function(h,params){
            	return h('i-switch',{
            		props:{
            			value:params.row.status==1?true:false,
            			size:'large'
            		},
            		on:{
            			'on-change':function(e){
            				if(params.row.status==1){
            					params.row.status=0
            				}else{
            					params.row.status=1
            				}
            				$vue.axios({
            					method:'get',
            					url:$store.state.app.globalUrl+"/admin/TestPaper/changeStatus?id="+params.row.Id+'&status='+params.row.status,
            					data:{}
            				}).then(function(res){
            					if(res.data.msg=="操作成功"){
            						$vue.$Message.success(e?'已启用':'已禁用');
            					}else{
            						$vue.$Message.error('操作失败');
            					}
            				});
            			}
            		}
            	},[h(
                		'span',
                		{slot:"open"},
                		'已启用'
            		),
            		h(
            			'span',
            			{slot:"close"},
            			'已禁用'
        			)
            	])
            }
        },
        {
            title: '操作',
            align: 'center',
            width:230,
            key: 'operate',
            render:function(h,params){
            	return h("div",[
            		h('Button',{
            			props:{
            				icon:'compose',
            				type:"primary",
            				size:'small'
            			},
            			on:{
            				click:function(){
            					router.push({
            						name:'edit-test',
            						query:{id:params.row.Id}
            					})
            				}
            			}
            		},'编辑'),
            		h('Button',{
            			props:{
            				icon:'ios-trash-outline',
            				type:"primary",
            				size:'small'
            			},
            			on:{
            				click:function(){
                                $vue.$Modal.confirm({
                                    content: '<h4>确定删除？</h4>',
                                    onOk: () => {
                                        $vue.axios({
                                            method:'get',
                                            url:$store.state.app.globalUrl+"/admin/TestPaper/del?id="+params.row.Id,
                                            data:{}
                                        }).then(function(res){
                                            $vue.$Message.success('已删除');
                                            router.push({
                                                name:'test-management',
                                                query:{time:Date.parse(new Date())}
                                            })
                                        });
                                    },
                                    onCancel: () => {
                                        $vue.$Message.info('已取消');
                                    }
                                })
            				}
            			}
            		},'删除'),
            		h('Button',{
            			props:{
            				icon:'ios-search',
            				type:"primary",
            				size:'small'
            			},
                        on:{
                            click:function(){
                                router.push({
                                    name:'preview-test',
                                    query:{id:params.row.Id}
                                })
                            }
                        }
            		},'预览')
            	])
            }
        }
        
    ];
